package com.wanggsx.library.base.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.HorizontalScrollView;

public class HorizontalScrollViewCanStop extends HorizontalScrollView {

    public HorizontalScrollViewCanStop(Context context) {
        super(context);
    }

    public HorizontalScrollViewCanStop(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public HorizontalScrollViewCanStop(Context context, AttributeSet attrs,
                                       int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private boolean isStoped = false;

    public void setStoped(boolean isStop) {
        this.isStoped = isStop;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (isStoped) {
            return false;
        } else {
            return super.onTouchEvent(ev);
        }
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (!isStoped) {
            getParent().requestDisallowInterceptTouchEvent(true);
        }
        return super.dispatchTouchEvent(ev);
    }


}
